//
//  MainViewController.swift
//  iOSProjectExtensionSwift
//
//  Created by HBGG on 2020/7/5.
//  Copyright © 2020 lidianchao. All rights reserved.
//

import UIKit
import Alamofire
class MainViewController: BaseViewController,UIScrollViewDelegate {
    
    var _scrollView = UIScrollView.init()
    // 数据库声明
    var database: DBManager!
    override func viewDidLoad() {
        super.viewDidLoad()
        login()
        showPage()
//        setImage()
        let button = UIButton.createButtonWithTitle(title: "ceshide", frame: CGRect(x: 100, y: 100, width: 100, height: 80), target: self, action: #selector(test), font: 14, textColor: .green)
        button.backgroundColor = .red
        button.addCornerRadius(radius: 4, borderWidth: 1, borderColor: .gray)
        self.view.addSubview(button)
        // Do any additional setup after loading the view.
    }
    @objc func test(button:UIButton) {
        // 与数据库建立连接
        database = DBManager()

        // 建立列表（有列表后不再建立）
        database.tableLampCreate()

        // 插入两条数据
        database.tableLampInsertItem(address: 51, name: "灯光1", colorValue: "#FFFFFF", lampType: 0)
        database.tableLampInsertItem(address: 52, name: "灯光2", colorValue: "#AAAAAA", lampType: 1)

        // 遍历列表（检查插入结果）
        database.queryTableLamp()

        // 根据条件查询
        database.readTableLampItem(address: 52)

        // 修改列表项
//        database.tableLampUpdateItem(address: 51, newName: "客厅大灯")

        // 遍历列表（检查修改结果）
//        database.queryTableLamp()

        // 删除列表项
//        database.tableLampDeleteItem(address: 52)

        // 遍历列表（检查删除结果）
//        database.queryTableLamp()
    }
    func setImage() {
        let image = UIImageView(image: UIImage(named: "Mine_Top_bgView"))
        image.frame = CGRect(x: 50, y: 150, width: 200, height: 100)
        self.view.addSubview(image)
        MainManager.sharedManager().upload(image: image.image!)
    }
    func login()  {
        let userName = "hyjcs01"
        let pwdBase64 = "Hyjcs010."
        MainManager.sharedManager().login(userName: userName, pwd: pwdBase64) { (result) in
            
        }
        
    }
    func showPage() {
//        MainManager.sharedManager().showPage()
//        MainManager.sharedManager().download()
        MainManager.sharedManager().getAnnouncelist()
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
